<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2012.03.17.
   家居公司列表显示($$)*/

!defined('Q_PATH') && exit;

class Index_C_Controller extends InitController{

	public function index(){
		$nDid=intval(Q::G('did','G'));
		$nHid=intval(Q::G('hid','G'));
		$nBid=intval(Q::G('bid','G'));
		$nCid=intval(Q::G('cid','G'));
		$nSid=intval(Q::G('sid','G'));

		// 载入相关缓存
		Core_Extend::loadCache('jiaju_class');
		Core_Extend::loadCache('jiaju_district'.Core_Extend::getCityCache());
		Core_Extend::loadCache('jiaju_cplisthotcompany'.Core_Extend::getCityCache());

		// 当前城市商家
		$arrWhere=array();
		$arrWhere['A.jiajucompany_status']=1;
		$arrWhere['string_']=Core_Extend::getCitySql('A.');

		// 属性筛选
		$arrJiajucompanyId=array();
		$bJiajucompanySelected=false;
		$sDistrictTitle=$sHomeclassTitle=$sBusinessclassTitle=$sCommunityTitle=$sStyleclassTitle='';
		if($nDid){
			$arrJiajucompanyId=Model::F_('jiajucompanydistrict','district_id=?',$nDid)->getColumn('jiajucompany_id',true);
			!$arrJiajucompanyId && $arrJiajucompanyId=array();
			$bJiajucompanySelected=true;
			$sDistrictTitle=Model::F_('district','district_id=?',$nDid)->getColumn('district_name');
		}
		if($nHid){
			$arrTemp=Model::F_('jiajucompanyhomeclass','jiajucompanyclass_id=?',$nHid)->getColumn('jiajucompany_id',true);
			!$arrTemp && $arrTemp=array();
			if($bJiajucompanySelected===true){
				$arrJiajucompanyId=array_intersect($arrJiajucompanyId,$arrTemp);
			}else{
				$arrJiajucompanyId=$arrTemp;
			}
			$bJiajucompanySelected=true;
			$sHomeclassTitle=Model::F_('jiajucompanyclass','jiajucompanyclass_id=?',$nHid)->getColumn('jiajucompanyclass_name');
		}
		if($nBid){
			$arrTemp=Model::F_('jiajucompanybusinessclass','jiajucompanyclass_id=?',$nBid)->getColumn('jiajucompany_id',true);
			!$arrTemp && $arrTemp=array();
			if($bJiajucompanySelected===true){
				$arrJiajucompanyId=array_intersect($arrJiajucompanyId,$arrTemp);
			}else{
				$arrJiajucompanyId=$arrTemp;
			}
			$bJiajucompanySelected=true;
			$sBusinessclassTitle=Model::F_('jiajucompanyclass','jiajucompanyclass_id=?',$nBid)->getColumn('jiajucompanyclass_name');
		}
		if($nCid){
			$arrWhere['A.community_id']=$nCid;
			$sCommunityTitle=Model::F_('district','district_id=?',$nCid)->getColumn('district_name');
		}
		if($nSid){
			$arrTemp=Model::F_('jiajucompanystyleclass','jiajucompanyclass_id=?',$nSid)->getColumn('jiajucompany_id',true);
			!$arrTemp && $arrTemp=array();
			if($bJiajucompanySelected===true){
				$arrJiajucompanyId=array_intersect($arrJiajucompanyId,$arrTemp);
			}else{
				$arrJiajucompanyId=$arrTemp;
			}
			$bJiajucompanySelected=true;
			$sStyleclassTitle=Model::F_('jiajucompanyclass','jiajucompanyclass_id=?',$nSid)->getColumn('jiajucompanyclass_name');
		}
		
		if($bJiajucompanySelected===true){
			$arrWhere['A.jiajucompany_id']=array('in',$arrJiajucompanyId?$arrJiajucompanyId:array(0));
		}

		$nTotal=Model::F_('jiajucompany','@A')->where($arrWhere)->getCounts();
		$oPage=Page::RUN($nTotal,10,Jiaju_Extend::getCompanyList(null,null,null,null,null,'{page}',false));
		$arrJiajucompanys=Model::F_('jiajucompany','@A')
			->setColumns('A.jiajucompany_authsys,A.jiajucompany_fullname,A.jiajucompany_logo,A.jiajucompany_isfvip,A.jiajucompany_isavip,A.jiajucompany_rank,A.jiajucompany_credit,A.jiajucompany_viewnum,A.jiajucompany_address,A.jiajucompany_foundingyear,A.jiajucompany_telephone,A.jiajucompany_id,A.jiajucompany_domain,A.jiajucompany_commentlevel,A.jiajucompany_packagenum,A.jiajucompany_casenum,A.jiajucompany_contactname')
			->where($arrWhere)
			->order('A.jiajucompany_rank DESC,A.jiajucompany_credit DESC,A.jiajucompany_id DESC')
			->limit($oPage->S(),$oPage->N())
			->getAll();

		Core_Extend::getSeo($this,array(
			'title'=>($sHomeclassTitle?"#cityname#{$sDistrictTitle}{$sHomeclassTitle}装修公司排行榜-":'').
				($sBusinessclassTitle?"#cityname#{$sDistrictTitle}{$sBusinessclassTitle}装修公司排行榜-":'').
				($sStyleclassTitle?"#cityname#{$sDistrictTitle}{$sStyleclassTitle}装修公司排行榜-":'').
				($sCommunityTitle?"公司办公地址位于#cityname#{$sDistrictTitle}{$sCommunityTitle}装修公司排行榜-":'').
				"#cityname#{$sDistrictTitle}装修公司排名-#cityname#{$sDistrictTitle}装修公司排行榜",
			'keywords'=>($sHomeclassTitle?"#cityname#{$sDistrictTitle}{$sHomeclassTitle}装修公司排行榜,":'').
				($sBusinessclassTitle?"#cityname#{$sDistrictTitle}{$sBusinessclassTitle}装修公司排行榜,":'').
				($sStyleclassTitle?"#cityname#{$sDistrictTitle}{$sStyleclassTitle}装修公司排行榜,":'').
				($sCommunityTitle?"公司办公地址位于#cityname#{$sDistrictTitle}{$sCommunityTitle}装修公司排行榜,":'').
				"#cityname#{$sDistrictTitle}装修公司排名,#cityname#{$sDistrictTitle}装饰公司,#cityname#{$sDistrictTitle}装修公司排行榜",
			'description'=>($sHomeclassTitle?"#cityname#{$sDistrictTitle}{$sHomeclassTitle}装修公司排行榜，":'').
				($sBusinessclassTitle?"#cityname#{$sDistrictTitle}{$sBusinessclassTitle}装修公司排行榜，":'').
				($sStyleclassTitle?"#cityname#{$sDistrictTitle}{$sStyleclassTitle}装修公司排行榜，":'').
				($sCommunityTitle?"公司办公地址位于#cityname#{$sDistrictTitle}{$sCommunityTitle}装修公司排行榜，":'').
				"#sitename#提供了#cityname#".($sDistrictTitle?$sDistrictTitle:'各区域')."的装修公司电话,及#cityname#{$sDistrictTitle}装修公司承接价位与服务类型，能够快速地帮助你找到满意的装修公司。",
		),true,true);

		$this->assign('arrJiajucompanys',$arrJiajucompanys);
		$this->assign('sPageNavbar',$oPage->P(array('id'=>'pagination','style'=>'li','current'=>'active')));
		$this->assign('arrDistricts',$GLOBALS['_cache_']['jiaju_district'.Core_Extend::getCityCache()]);
		$this->assign('arrCompanyClasss',$GLOBALS['_cache_']['jiaju_class']);
		$this->assign('arrPingpaiJiajucompanys',$GLOBALS['_cache_']['jiaju_cplisthotcompany'.Core_Extend::getCityCache()]['cp1']);
		$this->assign('arrPaihangJiajucompanys',$GLOBALS['_cache_']['jiaju_cplisthotcompany'.Core_Extend::getCityCache()]['cp2']);
		$this->assign('arrHotPingpaiJiajucompanys',$GLOBALS['_cache_']['jiaju_cplisthotcompany'.Core_Extend::getCityCache()]['cp3']);
		$this->assign('sDistrictTitle',$sDistrictTitle);
		$this->assign('sHomeclassTitle',$sHomeclassTitle);
		$this->assign('sBusinessclassTitle',$sBusinessclassTitle);
		$this->assign('sCommunityTitle',$sCommunityTitle);
		$this->assign('sStyleclassTitle',$sStyleclassTitle);
		$this->display();
	}

}
